package com.牛客网.jd;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public class 小山问题 {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (scanner.hasNext()) {
			int count = scanner.nextInt();
			int numbers[] = new int[count];
			for (int i = 0; i < count; i++) {
				numbers[i] = scanner.nextInt();
			}
			boolean haha = true;
			for (int i = 0; i < numbers.length - 1; i++) {
				if (numbers[i + 1] != numbers[i]) {
					haha = false;
					break;
				}
			}
			if (haha) {
				System.out.println((numbers.length * (numbers.length - 1)) / 2);
				return;
			}
			Set<String> set = new TreeSet<>();
			// int lookCount=count;
			for (int i = 0; i < numbers.length; i++) {
				int begin = (i + 1 + count) % count;
				int end = (i - 1 + count) % count;
				for (int j = begin;;) {
					if (j == end) {
						break;
					}
					if (numbers[j] <= numbers[i]) {
						// lookCount++;
						j = (j + 1 + count) % count;
						if (j != end) {
							if (!set.contains(i + " " + (j)) && !set.contains((j) + " " + i)) {
								set.add(i + " " + (j));
							}
						}
					} else {
						break;
					}
				}
			}
			for (Iterator iterator = set.iterator(); iterator.hasNext();) {
				String string = (String) iterator.next();
				System.out.println(string);
			}
			System.out.println(count + set.size());
		}
	}
}
